package cc.geguo.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者  Administrator
 * 时间  2017/3/15 20:08
 * 文件  AjaxDemo40
 * 描述  通过Ajax 实现Post请求
 */
@WebServlet(name = "AjaxPostServlet",urlPatterns = "/post")
public class AjaxPostServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		String u8name = new String(username.getBytes("iso8859-1"),"utf-8");

		response.setContentType("text/html;charset=utf-8");
		PrintWriter print = response.getWriter();
		if (username!=null){
			print.write("<span>你的用户"+u8name+"<span>");

		}else {
			print.write("我不知道你输入了啥");
		}
		print.flush();
		print.close();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String username = request.getParameter("username");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter print = response.getWriter();
		if (username!=null){
			print.write("<span>你的用户"+username+"<span>");

		}else {
			print.write("我不知道你输入了啥");
		}
		print.flush();
		print.close();
	}
}
